﻿using System;
using System.Collections;
using System.Collections.Generic;
using Me.Prettyprint.Cassandra.Connection;
using Me.Prettyprint.Cassandra.Model.Thrift;
using Me.Prettyprint.Cassandra.Serializers;
using Me.Prettyprint.Cassandra.Service;
using Me.Prettyprint.Cassandra.Utils;
using Me.Prettyprint.Hector.Api;
using Me.Prettyprint.Hector.Api.Beans;
using Me.Prettyprint.Hector.Api.Query;
using Org.Apache.Cassandra.Thrift;

namespace Me.Prettyprint.Cassandra.Model.Thrift
{
    /// <summary>
    /// Class provides methods that translate from Hector consistency level to
    /// Cassandra consistency level. This is inherited from Java Hector. Hector
    /// did this because Cassandra was changing rapidly between 2011-2013, so
    /// it made sense to do the conversion. In the future, it might be good
    /// to remove the conversion.
    /// </summary>
    public class ThriftConverter
    {
        public static ConsistencyLevel consistencyLevel(HConsistencyLevel c) {
            switch (c) {
                case HConsistencyLevel.ALL:
                    return ConsistencyLevel.ALL;
                case HConsistencyLevel.ANY:
                    return ConsistencyLevel.ANY;
                case HConsistencyLevel.ONE:
                    return ConsistencyLevel.ONE;
                case HConsistencyLevel.TWO:
                    return ConsistencyLevel.TWO;
                case HConsistencyLevel.THREE:
                    return ConsistencyLevel.THREE;
                case HConsistencyLevel.QUORUM:
                    return ConsistencyLevel.QUORUM;
                case HConsistencyLevel.EACH_QUORUM:
                    return ConsistencyLevel.EACH_QUORUM;
                case HConsistencyLevel.LOCAL_QUORUM:
                    return ConsistencyLevel.LOCAL_QUORUM;
                default:
                    throw new InvalidOperationException("Unregornized consistency level " + c);
            }
        }
        public static List<Column> getColumnList(List<ColumnOrSuperColumn> columns)
        {
            List<Column> list = new List<Column>(columns.Count);
            foreach (ColumnOrSuperColumn col in columns)
            {
                list.Add(col.Column);
            }
            return list;
        }
    }
}
